import java.util.Arrays;
import java.util.Scanner;

public class note_Method {

    //1.三次输入密码（判断字符串相等的函数）
    public static void main1(String[] args) {
        String pad="21klo";
        int t=3;
        while(t!=0){
            System.out.println("请输入密码：");
            Scanner scan=new Scanner(System.in);

            String temp=scan.nextLine();
            if(temp.equals(pad)){
                System.out.println("恭喜你！密码正确");
                break;
            }
            else{
                t--;
                System.out.println("密码错误！你还有"+t+"次机会！");
                if(t==0){
                    System.out.println("登陆失败！");
                }
            }

        }

    }


    //2.用递归求n的阶乘

    public static int factorial(int temp){
        if(temp==1){
            return 1;
        }
        return temp*factorial(temp-1);
    }


    public static void main2(String[] args) {
        System.out.println("输入一个整数：");
        Scanner scan=new Scanner(System.in);
        int x= scan.nextInt();
        System.out.println(factorial(x));
    }

    //3.用递归打印每一位：1234打印1  2  3  4
    public static void prt(int n){
        if(n<10){
            System.out.print(n+" ");
        }
        else{
            prt(n/10);
            System.out.print(n%10+" ");

        }
    }
    public static void main3(String[] args) {
        prt(9234);
    }

    //4.用递归求1+2+3+4+...+10

    public static int add(int x){
        if(x==1){
            return x;
        }
        return x+add(x-1);
    }
    public static void main4(String[] args) {
        System.out.println(add(10));
    }

    //5.用递归求：1234，返回1+2+3+4=10

    public static int everyAdd(int x){
        if(x<10){
            System.out.print(x);
            return x;
        }
        else{

            int last=x%10;
            int sum=everyAdd(x/10);
            System.out.print("+"+last);
            return last+sum;

        }
    }
    public static void main5(String[] args) {
        System.out.print("="+everyAdd(234));
    }

    //6.递归求斐波那契数列
    public static int fib(int n){
        if(n==1||n==2){
            return 1;
        }
        return fib(n-2)+fib(n-1);
    }
    public static void main6(String[] args) {

        Scanner scan=new Scanner(System.in);
        System.out.println("请输入一个整数：");
        int n= scan.nextInt();
        System.out.println(fib(n));
    }

    //7.递归求汉诺塔


    public static void hanoi(int n,char A,char B,char C){
        if(n==1){
            System.out.println(A+"->"+C);
        }
        else{
            hanoi(n-1,A,C,B);
            System.out.println(A+"->"+C);
            hanoi(n-1,B,A,C);
        }
    }
    public static void main7(String[] args) {
        hanoi(3,'S','M','E');
    }




    //8.for-each输出数组元素
    public static void main(String[] args) {
        int[] arr1=new int[5];
        arr1[0]=9;
        for(int temp:arr1){
            System.out.print(temp+" ");
        }

        String ret=Arrays.toString(arr1);
        System.out.println(ret);
    }

    //9.
    public static void main9(String[] args) {

        int[] arr = new int[]{1, 2, 3, 4, 5, 6};
        int len = arr.length;
        System.out.println("arr=" + len);

        double[] arr2 = {1.3, 4, 6.9};
        int len2 = arr2.length;
        System.out.println("arr2=" + len2);

        char[] arr3 = {'a', 's', 'e', 'p', 'e', 'e'};
        int len3 = arr3.length;
        System.out.println("arr3=" + len3);

        String[] arr4={"sdf","gbf"};
        int len4 = arr4.length;
        System.out.println("arr4=" + len4);
    }
}
